home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TPUG - Toronto PET Users Group
/
TPUG Users Group CD
/
TPUG Users Group CD.iso
/
AMIGA
/
AMICUS
/
AMICUS21.ADF
/
PropGadget
/
prop.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-01-27
|
14KB
|
523 lines
/*********************************************************
'C' program showing examples of Proportional Gadgets.
This was compiled using Manx, Aztec "C", AmigaDos V1.2
The code depends on V1.2 functions to operate correctly.
It is intended to be run from CLI.
Copyright (C) 1987 H. Maybeck Tolly, TollySoft
This program is in the public domain and may be
distributed free of charge.
**********************************************************/
#include <exec/types.h>
#include <exec/exec.h>
#include <intuition/intuition.h>
#include <graphics/gfxbase.h>
#include <functions.h>
#define visible_lines 5L
#define total_lines 10L
#define MAXLEN 20
struct IntuitionBase *IntuitionBase = 0L;
struct GfxBase *GfxBase = 0L;
struct Window *ControlWindow = 0L;
struct IntuiMessage *MyIntuiMessage;
/***********************************/
/* Declare Prop Gadget structures. */
/***********************************/
/* This Prop Gadget shows how to read Pot values to */
/* scroll through a list of strings. */
struct Image g_image_scroll;
struct PropInfo g_prop_scroll;
struct Gadget PropGadget_scroll = {
NULL, /* pointer to Next Gadget */
180, 30, 20, 60, /* (Left Top Width Height) Hit Box */
GADGHCOMP , /* Flags */
/* Activation flags */
GADGIMMEDIATE | FOLLOWMOUSE | RELVERIFY,
PROPGADGET , /* Type */
(APTR)&g_image_scroll, /* pointer to Image */
NULL, /* no pointer to SelectRender */
NULL, /* pointer to GadgetText */
0, /* MutualExclude not implemented*/
(APTR)&g_prop_scroll, /* pointer to SpecialInfo */
0, /* no ID */
NULL /* no pointer to special data */
};
/* This Prop Gadget points to a disabled String Gadget, */
/* to show a "Prop Fuzzy". */
/* This String Gadget is used only to show a property */
/* of Prop Gadgets. It is not intended as a clear example*/
/* of a string gadget. Please refer to previous articles */
/* in this series for more info on String Gadgets. */
struct StringInfo StrInfo = {
(UBYTE *)"static test string ",
NULL, 0, 20, 0,0,0,0,0,0,NULL,0,NULL};
struct Gadget StrGadget = {
&PropGadget_scroll,
220,30,160,7,
GADGHCOMP | GADGDISABLED ,
GADGIMMEDIATE | RELVERIFY,
STRGADGET,
NULL, NULL, NULL, 0, (APTR)&StrInfo, 0, NULL
};
struct Image g_image_fuzzy;
struct PropInfo g_prop_fuzzy;
struct Gadget PropGadget_fuzzy = {
&StrGadget, /* pointer to Next Gadget */
400, 30, 20, 60, /* (Left Top Width Height) Hit Box */
GADGHCOMP , /* Flags */
GADGIMMEDIATE | RELVERIFY, /* Activation flags */
PROPGADGET , /* Type */
(APTR)&g_image_fuzzy, /* pointer to Image */
NULL, /* no pointer to SelectRender */
NULL, /* pointer to GadgetText */
0, /* MutualExclude not implemented*/
(APTR)&g_prop_fuzzy, /* pointer to SpecialInfo */
0, /* no ID */
NULL /* no pointer to special data */
};
/********************************************************/
/* All images must reside in chip memory (lower 512K). */
/* If your compiler/linker does not have an option to do*/
/* this, you must allocate chip memory, and copy this */
/* data into that memory before assigning the pointer */
/* members of the Gadget structure. */
/********************************************************/
UWORD prime[] =
{
/* plane 1 */
0x0200,
0x0700,
0x0700,
0x0F80,
0x0F80,
0x1FC0,
0x1FC0,
0x3FE0,
0x7FF0,
0x3FE0,
0x1FC0,
0x1FC0,
0x0F80,
0x0F80,
0x0700,
0x0700,
0x0200,
/* plane 2 */
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF
};
UWORD alt[] =
{
/* plane 1 */
0x7038,
0x3870,
0x1CE0,
0x0FC0,
0x0FC0,
0x0FC0,
0x0FC0,
0x0FC0,
0x0FC0,
0x0FC0,
0x0FC0,
0x0FC0,
0x0FC0,
0x0FC0,
0x1CE0,
0x3870,
0x7038,
/* plane 2 */
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF,
0xFFFF
};
struct Image g_image_primary = {
1,0,13,17,2,
prime,
0x03, 0x0, NULL
};
struct Image g_image_alternate = {
1,0,13,17,2,
alt,
0x03, 0x0, NULL
};
struct PropInfo g_prop_image;
struct Gadget PropGadget_image = {
&PropGadget_fuzzy, /* pointer to Next Gadget */
500, 30, 21, 60, /* (Left Top Width Height) Hit Box */
GADGIMAGE | GADGHIMAGE, /* Flags */
GADGIMMEDIATE | RELVERIFY, /* Activation flags */
PROPGADGET , /* Type */
(APTR)&g_image_primary, /* pointer to Image */
(APTR)&g_image_alternate,/* no pointer to SelectRender*/
NULL, /* pointer to GadgetText */
0, /* Mut-Exc not implemented */
(APTR)&g_prop_image, /* pointer to SpecialInfo */
0, /* no ID */
NULL /* no special data */
};
struct Image g_image_free = {
1,0,13,17,2,
alt,
0x03, 0x0, NULL
};
struct PropInfo g_prop_free;
struct Gadget PropGadget_free = {
&PropGadget_image, /* pointer to Next Gadget */
200, 120, 80, 35, /* (Left Top Width Height) Hit Box */
GADGHNONE | GADGIMAGE, /* Flags */
GADGIMMEDIATE | RELVERIFY, /* Activation flags */
PROPGADGET , /* Type */
(APTR)&g_image_free, /* pointer to Image */
NULL, /* no SelectRender */
NULL, /* pointer to GadgetText */
0, /* Mut-Excl not implemented */
(APTR)&g_prop_free, /* pointer to SpecialInfo */
0, /* no ID */
NULL /* no pointer to special data */
};
/********************************************************/
/* IntuiText structures for the list of items to scroll */
/********************************************************/
struct IntuiText IntuiStr[5] = {
{2,3,JAM2,5,30,NULL,NULL,NULL},
{2,3,JAM2,5,45,NULL,NULL,&IntuiStr[0]},
{2,3,JAM2,5,60,NULL,NULL,&IntuiStr[1]},
{2,3,JAM2,5,75,NULL,NULL,&IntuiStr[2]},
{2,3,JAM2,5,90,NULL,NULL,&IntuiStr[3]}
};
/********************************************************/
/* Text strings through which to scroll. */
/* In our example they will retain the same values */
/* throughout the program. In a real application they */
/* would most likely change. We won't pad them with */
/* blanks now, so that we can show how to do it on */
/* the fly. */
/********************************************************/
char text_strings[10][20] = {
{"first string"},
{"second string"},
{"third string"},
{"fourth string"},
{"fifth string"},
{"sixth string"},
{"seventh string"},
{"eighth string"},
{"ninth string"},
{"tenth string"}
};
/********************************************************/
/* Labels for different Prop Gadgets */
/* Harri Tolly is not the Bandito */
/********************************************************/
struct IntuiText labels[4] = {
{2,0,JAM2,5,15,NULL,
(UBYTE *)"scroll strings",NULL},
{2,0,JAM2,220,15,NULL,
(UBYTE *)"Prop fuzzy",&labels[0]},
{2,0,JAM2,470,15,NULL,
(UBYTE *)"image/highlight",&labels[1]},
{2,0,JAM2,200,108,NULL,
(UBYTE *)"free Vert and Horiz",&labels[2]}
};
/********************************/
/* Declare NewWindow structure. */
/********************************/
struct NewWindow NewControlWindow = {
20, 20, /* start LeftEdge, TopEdge */
600, 160, /* start Width, Height */
2, 3, /* DetailPen, BlockPen */
/* IDCMP FLAGS */
GADGETUP | GADGETDOWN | CLOSEWINDOW |
MOUSEMOVE | MENUPICK,
/* Flags */
WINDOWDRAG | WINDOWDEPTH | WINDOWCLOSE | ACTIVATE,
&PropGadget_free, /* Pointer to FirstGadget */
NULL, /* no pointer to first CheckMark */
(UBYTE *)"Proportional Gadgets",/* Title */
NULL, /* no Pointer to Screen */
NULL, /* no Pointer to BitMap */
20, 20, /* Min size (no size allowed) */
600, 160, /* Max size (no size allowed) */
WBENCHSCREEN /* Type of screen */
};
/****************************************************/
/* Main program */
/****************************************************/
main()
{
struct MenuItem *ItemAddress();
ULONG Signals, MIClass, MICode, itemnum;
APTR MIAddress;
LONG gad_pos, real_pos;
SHORT MouseX, MouseY, first_line;
BOOL fix_strings;
/* Open libraries */
if (!(IntuitionBase = (struct IntuitionBase *)
OpenLibrary("intuition.library",
(LONG)LIBRARY_VERSION)))
{
printf("Can't open the intuition library\n");
MyCleanup();
exit(FALSE);
}
if (!(GfxBase = (struct GfxBase *)
OpenLibrary("graphics.library",
(LONG)LIBRARY_VERSION)))
{
printf("Can't open the graphics library\n");
MyCleanup();
exit(FALSE);
}
/*****************************************************/
/* Set Prop Gadget variables for and motion */
/* of knob. */
/*****************************************************/
g_prop_scroll.Flags = AUTOKNOB | FREEVERT;
g_prop_scroll.VertBody = (ULONG)(visible_lines * 0xFFFF)
/ total_lines;
g_prop_fuzzy.Flags = AUTOKNOB | FREEVERT;
g_prop_fuzzy.VertBody = 0x3000;
g_prop_image.Flags = FREEVERT;
g_prop_image.VertBody = 0x3000;
g_prop_free.Flags = FREEVERT | FREEHORIZ | PROPBORDERLESS;
g_prop_free.VertBody = 0x7FFF;
g_prop_free.HorizBody = 0x7FFF;
/*****************************************************/
/* Call routine to assign strings to the IntuiText */
/* structures. We'll start at the top of the list. */
/*****************************************************/
SetString(0);
PadString();
/*********************************************************/
/* Open window in which to display Proportional Gadgets. */
/*********************************************************/
if (!(ControlWindow =
(struct Window *)OpenWindow(&NewControlWindow)))
{
printf("Couldn't open the control window.\n");
MyCleanup();
exit(FALSE);
}
PrintIText(ControlWindow->RPort, &labels[3], 0L, 0L);
/************************************************/
/* Write out the strings to the window. */
/************************************************/
PrintIText(ControlWindow->RPort, &IntuiStr[4], 0L, 0L);
/*********************************************************/
/* Loop forever until user clicks Close Gadget on window.*/
/*********************************************************/
for (;;) { /* wait for a signal and process it */
fix_strings = FALSE;
Signals = Wait(1L <<
ControlWindow->UserPort->mp_SigBit);
/* Process the Intuition message. */
while (MyIntuiMessage=(struct IntuiMessage *)
GetMsg(ControlWindow->UserPort))
{
/* Get all the needed info and reply to message */
MIClass = MyIntuiMessage->Class;
MICode = MyIntuiMessage->Code;
MIAddress = MyIntuiMessage->IAddress;
MouseX = MyIntuiMessage->MouseX;
MouseY = MyIntuiMessage->MouseY;
ReplyMsg(MyIntuiMessage);
/* Determine what the message was. */
switch (MIClass)
{
case GADGETUP:
first_line = ((ULONG)(total_lines -
visible_lines) * g_prop_scroll.VertPot
+ (1L<<15)) >>16;
SetString(first_line);
PadString();
PrintIText(ControlWindow->RPort,
&IntuiStr[4], 0L, 0L);
break;
case GADGETDOWN:
break;
case MOUSEMOVE:
/****************************************************/
/* We'll set a flag to tell ourselves to update the */
/* strings. This way we don't update them for EVERY */
/* mousemove message. */
/****************************************************/
fix_strings = TRUE;
break;
/* User clicked close Gadget. */
case CLOSEWINDOW:
/* Reply to any outstanding messages. */
while (MyIntuiMessage =(struct IntuiMessage *)
GetMsg(ControlWindow->UserPort))
ReplyMsg(MyIntuiMessage);
MyCleanup();
exit(TRUE);
break;
} /* switch */
} /* while */
/********************************************************/
/* Check if we need to update list of strings. */
/* Call routine to assign strings to the IntuiText */
/* structures. */
/********************************************************/
if (fix_strings)
{
first_line = ((ULONG)(total_lines - visible_lines) *
g_prop_scroll.VertPot + (1L<<15)) >>16;
SetString(first_line);
PadString();
PrintIText(ControlWindow->RPort,
&IntuiStr[4], 0L, 0L);
}
} /* for */
} /* main */
MyCleanup()
{
if (ControlWindow) CloseWindow(ControlWindow);
if (GfxBase) CloseLibrary(GfxBase);
if (IntuitionBase) CloseLibrary(IntuitionBase);
}
/********************************************************/
/* This routine assigns a string to each of the */
/* IntuiText structures we will display. */
/********************************************************/
SetString(index)
WORD index;
{
int i;
for(i=0; i<5; i++)
IntuiStr[i].IText = (UBYTE *)text_strings[index + i];
}
/********************************************************/
/* This routine will pad each string we have decided */
/* to display with blanks. In this example it is */
/* redundant - we will blank out the same strings over */
/* over. In a real application, however, we would most */
/* likely be changing the text in the text_strings array*/
/* and would therefore need to re-blank them. */
/********************************************************/
PadString()
{
int len,i,j;
for (i=0; i<5; i++)
{
len = strlen(IntuiStr[i].IText);
for (j = len; j < MAXLEN - 1; j++)
{
* (IntuiStr[i].IText + j) = ' ';
}
* (IntuiStr[i].IText + MAXLEN - 1) = '\0';
}
}